<?php
class IndexAction extends BaseAction {
	
	public function index(){
		
		$this->display();
	}
	
	public function reg(){
		
		$Special=D('Special')->order('id desc')->findall();
		$this->assign('Special',$Special);
		$this->display();
	}
	
	public function register(){
		
		$data=$_POST;
		$User=D("User");
        if($User->create()) { 
        	$User->password=md5($data['password']);
        	$User->groupid = 1;
        	$User->ischecked = 1;
            if($User->add()){ 
            	$this->assign('jumpUrl','index');
				$this->success(L('_INSERT_SUCCESS_'));
            }else{ 
                $this->error(L(_INSERT_FAIL_)); 
            } 
        }else{ 
            $this->error($User->getError()); 
        }
		
	}
	
	public function login(){
		
		$Special=D('Special')->order('id desc')->findall();
		$this->assign('Special',$Special);
		$this->display();
	}
	
	public function checkLogin()
	{
		$loginUser=D('User');

		$username=trim($_POST['username']);
		$password=trim($_POST['password']);
		
//		$seccode=trim($_POST['seccode']);
		if($username=='')
		{
			$this->error('用户名不能为空!!!');
		}elseif($password==''){
			$this->error('密码不能为空!!!');
		}
		$map=array();
		$map["username"]=$username;
		$user=$loginUser->find($map);
		dump($user);
		if(false===$user){
			$this->error('用户名不存在!!!');
		}else{
			if($user['password']!=md5($password))$this->error('密码错误!!!');
			if($user['ischecked']!=1)$this->error('用户被锁定');
//			if($user['groupid']==2)$this->error('用户组被限制登录系统，请联系管理员');
			
			Session::set(C('USER_AUTH_KEY'),$user['id']);
			Session::set('username',$user['username']);
			Session::set('groupid',$user['groupid']);
			$this->success(L('_INSERT_SUCCESS_'));
			$this->redirect("index");
		}
	}
	
	
	function verify()
	{
		import('ORG.Util.Image');
		if(isset($_REQUEST['adv']))
		{
			Image::showAdvVerify();
		}
		else
		{
			Image::buildImageVerify();
		}
	}
}
?>